﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Serialization;
using LayoutPlanning.Model;

namespace LayoutPlanning.Model.ImmaModels
{
	[Serializable]
	public class Simulation
	{
		public string note { get; set; }

		public PlanningParameters PlanningParameters { get; set; }

		public Plant Plant { get; set; }

		public Process[] Experiments { get; set; }

		public SimultionResult SimultionResult { get; set; }
	}
    [Serializable]

    public class PlanningParameters
	{
		private TimeSpan _time;
		public decimal Clearance { get; set; }

		public decimal EuclideanDistance { get; set; }

		public TimeSpan TimeSpanType
		{
			get { return _time; }
			set { _time = value; }
		}
		public string CycleTime
		{
			get { return TimeSpanType.ToString(); }
			set
			{
				if (string.IsNullOrEmpty(value))
					return;

				TimeSpan.TryParse(value, out _time);
			}
		}

		public decimal Smoothness { get; set; }

		public decimal PenaltyFunction { get; set; }

		public int NumberOfViaLocations { get; set; }
	}

    [Serializable]
    public class Plant
	{
		public Workshop[] Workshops { get; set; }
	}
    [Serializable]
    public class Workshop
	{
		public String Name { get; set; }

		public Grafics Grafics { get; set; }

		public double Width { get; set; }
		public double Height { get; set; }

		public Workstation[] Workstations { get; set; }

	}
    [Serializable]

    public class Grafics
    {
        [XmlElement()]
        public Square[] Square;
        [XmlElement()]
        public Box[] Box;
        [XmlElement()]
        public Cad[] Cad;
        [XmlElement()]
        public PointCloud[] PointCloud;
        [XmlElement()]
        public Circle[] Circle;
        [XmlElement()]
        public Cylinder[] Cylinder;
    }

    public class Grafic { }
    [Serializable]
    public class PointCloud : Grafic
	{
		public string File { get; set; }
	}
    [Serializable]
    public class Box : Grafic
	{
		public double Width { get; set; }
		public double Hight { get; set; }
		public double Depth { get; set; }
	}
    [Serializable]
    public class Cylinder : Grafic
	{
		public double Diameter { get; set; }
		public double Hight { get; set; }
	}
    [Serializable]
    public class Cad : Grafic
	{
		public string File { get; set; }
		public double Type { get; set; }
	}
    [Serializable]
    public class Workstation
	{
		public Point Position { get; set; }
		public double Width { get; set; }
		public double Height { get; set; }
		public double Rotation { get; set; }
		[XmlElement()]
		public Obstacle[] Obstacles { get; set; }
		[XmlElement("Machine")]
		public Machine[] Machines { get; set; }
		[XmlElement("Storage")]
		public Storage[] Storages { get; set; }
		
	}
    [Serializable]
    public class PhysicalPlace
	{
		public String Name { get; set; }

		
		public Point Position { get; set; }
		public double Rotation { get; set; }

		

	}

    [Serializable]
    public class Machine:PhysicalPlace
	{
		public ReferencePoint[] ReferencePoints { get; set; }

        
        public Grafics Grafics { get; set; }
	}


    [Serializable]
    public class ReferencePoint
	{
		public String Name { get; set; }

		public Point Position { get; set; }

		public double OperationDirection { get; set; }
	}



    [Serializable]
    public class Obstacle:PhysicalPlace
	{
		public Grafics Grafics { get; set; }
	}
    [Serializable]
    public class Square : Grafic
	{
		public double Width { get; set; }
		
		public double Height { get; set; }
	}
    [Serializable]

    public class Circle : Grafic
	{
		public double Radius { get; set; }
		
	}
    [Serializable]
    public class Storage : PhysicalPlace
	{
		public ReferencePoint[] ReferencePoints { get; set; }
		public Grafics Grafics { get; set; }
		public ProductReferece[] ProductRefereces { get; set; }
	}
    [Serializable]
    public class ProductReferece
	{
		[XmlAttribute]
		public string Ref { get; set; }
	}
    [Serializable]

    public class Process
	{
		public Instruction[] Instructions { get; set; }
	}


    [Serializable]
    public class Instruction
	{
		private TimeSpan _time;
		public String Name { get; set; }

		public String ManikinInstruction { get; set; }
		[XmlIgnore]
		public TimeSpan TimeSpanType
		{
			get { return _time; }
			set { _time = value; }
		}
		public string ProcessTime
		{
			get { return TimeSpanType.ToString(); }
			set
			{
				if (string.IsNullOrEmpty(value))
					return;

				TimeSpan.TryParse(value, out _time);
			}
		}

		public string ReferencePoint1 { get; set; }
		public string ReferencePoint2 { get; set; }
		public ProductReferece ProductReference { get; set; }
	}
    [Serializable]
    public class SimultionResult
	{
		public string ProcessReference { get; set; }
	
		public Path[] Paths { get; set; }
	}

    [Serializable]
    public class Path
	{
		private TimeSpan _time;
		public String ManikinInstruction { get; set; }

		[XmlIgnore]
		public TimeSpan TimeSpanType
		{
			get { return _time; }
			set { _time = value; }
		}

		public string Time
		{
			get { return TimeSpanType.ToString(); }
			set
			{
				if (string.IsNullOrEmpty(value))
					return;

				TimeSpan.TryParse(value, out _time);

			}
		}

		public Decimal ErgonomicScore { get; set; }

		public String Failure { get; set; }

	}
}